<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/layout :: common_header(~{::title},~{::link})">
<title>角色管理</title>
 <!-- 
  additional css  -->

</head>
 
<body>
	<div class="main-container">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="row">
					<div class="col-xs-12">
						<form action="" class="form-inline" id="clientForm">
							 <label>客户电话：</label><input
								type="text" name="clienttelephone">
							<button class="btn btn-primary btn-rounded btn-outline btn-sm "
							 type="button"	onclick="search()">
								<i class="fa fa-search"></i> 查询
							</button>
							<button class="btn btn-primary btn-rounded btn-outline btn-sm "
								type="reset">
								<i class="fa fa-refresh"></i> 重置
							</button>
						</form>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-12">
						<div class="pull-left">
							<button class="btn btn-primary btn-sm" data-toggle="tooltip"
								data-placement="left" onclick="add()" title="添加">
								<i class="fa fa-plus"></i> 添加
							</button>
							<button class="btn btn-success btn-sm" data-toggle="tooltip"
								data-placement="left" onclick="edit()" id="edit" title="修改">
								<i class="glyphicon glyphicon-edit"></i> 修改
							</button>
							<button class="btn btn-danger btn-sm" onclick="del()" id="delete"
								data-toggle="tooltip" data-placement="top">
								<i class="fa fa-trash-o"> 删除</i>
							</button>
						</div>
						<div class="pull-right"></div>
					</div>
				</div>
				 
				<div class="row">
					<div class="col-xs-12">
						<table id="clienttable"  data-toggle="table" data-side-pagination="server"
						data-striped="true"  data-query-params="queryParams" data-pagination-loop="false"
               			data-page-number="1" data-data-field="list" data-total-field="totalRow"
               			data-content-type="application/x-www-form-urlencoded" data-click-to-select="true"
               			data-pagination="true" data-method="post"  th:data-url="@{/sys/client/query}"  >
               			<thead>
										<tr>
											<th class="center" data-checkbox="true"> </th>
											<th   data-field="id"> ID</th>
											<th data-field="clientno">客户编号</th>
											<th class="center" data-field="clientname" data-formatter="nameFormatter">客户姓名</th>
											<th data-field="clienttelephone">电话</th>
											<th data-field="clientsex">性别</th>
											<th data-field="isclientmember">是否会员</th>
											<th data-field="filepath" >客户资料目录</th>
											<th data-field="id" data-formatter="optFormatter">操作</th>
										</tr>
									</thead>
						</table>
					</div>
				</div>
				<!-- /.col -->
			</div>

		</div>
		<!-- end main container -->
	</div>

<div th:replace="common/commonJS"></div>
	 <script>

	 function queryParams(params){
		 var temp = $("#clientForm").serializeJSON();
		 temp.pageSize=params.limit;   //页面大小
		 temp.pageNumber=(params.offset / params.limit) + 1;   //页码  
		 temp.sort=params.sort;      //排序列名  
		 temp.sortOrder=	 params.order; //排位命令（desc，asc）
		 return temp; 
	 }


	 function add(){
		 jp.openWindow("新增"+'客户',"sys/client/add","800px", "360px");
	 }

	 function edit(id){
		 if(!id){
			 var selectRows=$('#clienttable').bootstrapTable('getSelections');
			 if(selectRows.length==0){
				 jp.alert("未选择任何行");
				 return
			 }else if(selectRows.length>1){
				 jp.alert("只能修改一行");
				 return
			 }
			 id = getIdSelections();
		 }
		 jp.openWindow("修改"+'客户',ctx+"sys/client/edit/"+id,"800px", "550px");

	 }

	 function getIdSelections() {
		 return $.map($("#clienttable").bootstrapTable('getSelections'), function (row) {
			 return row.id
		 });
	 }

	 function search(){
		 $('#clienttable').bootstrapTable('refresh');
	 }

	 function del(ids){
		 //layer.confirm("确定要删除吗"){}
		 var selectRows=$('#clienttable').bootstrapTable('getSelections');
			ids =  getIdSelections();
		    jp.confirm('确定要删除选择的客户吗？', function (){
						 jp.loading();
						 $.get(ctx+"sys/client/deleteAll?ids=" +ids, function(data){
							 if(data){
								 $('#clienttable').bootstrapTable('refresh');
								 jp.success("删除成功");
							 }else{
								 jp.error("删除失败");
							 }
						 })

					 }

			 );
		 }



	 $(function () {
		 $('#clienttable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
				 'check-all.bs.table uncheck-all.bs.table', function () {
			 $('#delete').prop('disabled', ! $('#clienttable').bootstrapTable('getSelections').length);
			 $('#edit').prop('disabled', $('#clienttable').bootstrapTable('getSelections').length!=1);
		 });
	 });
	 function optFormatter(value,row,index){
		 return "<div class='hidden-sm hidden-xs btn-group'>"+
				 "<button class='btn btn-xs btn-info' onclick='editaccount("+value+")'>账号管理</button>"
				 +"<button class='btn btn-xs btn-info' >客户信息补充表</button>"
				 +"<button class='btn btn-xs btn-info'>客户信息资产表</button>"
				 +"</div>"
	 }

	 function optFormatterfilepath(value,row,index){
		 return "<div class='hidden-sm hidden-xs btn-group'>"+
				 "<a href='javascript:;' onclick='openFileIIs("+value+")'>打开目录</a>"
				 +"</div>"
	 }

	 function  nameFormatter(value,row,index){
		 return "<a href='javascript:;' onclick='edit("+row.id+")'>"+value
		 "</a>"

	 }

	 function editaccount(id){
		 if(!id){
			 var selectRows=$('#clienttable').bootstrapTable('getSelections');
			 if(selectRows.length==0){
				 jp.alert("未选择任何行");
				 return
			 }else if(selectRows.length>1){
				 jp.alert("只能修改一行");
				 return
			 }
			 id = getIdSelections();
		 }
		 jp.openWindow("客户"+'账号信息',ctx+"sys/client/editlist/"+id,"1000px", "550px");

	 }


	 function openFileIIs(filename){
		 try {
			 // var command = "\\\\192.168.1.155\\share\\" + command;
			 window.oldOnError = window.onerror;
			 window._command = command;
			 window.onerror = function (err) {
				 if (err.indexOf('automation') != -1) {
					 alert("命令" + window._command + "已经被用户禁止!");
					 return true;
				 }
				 else return false;
			 }
			 var wsh = new ActiveXObject("WScript.Shell");
			 if (wsh)
				 wsh.Run(command);
			 window.onerror = window.oldOnError;
		 }
		 catch (e) {
			 alert("附件文件夹不存在!");
		 }

	 }





	 </script>
</body>
</html>